#! /usr/bin/env python

import numpy as np;
import matplotlib.pyplot as mp;

def plot_tangent_arrow_field(eqderx,eqdery,xint,yint):
    """Function that plots the tangent arrow field of the given 2D-differential equation"""
    pace=0.5    
    X = np.arange(-xint/2,xint/2+1,pace)
    Y = np.arange(-yint/2,yint/2+1,pace)
    Xvect = np.zeros(xint*yint)
    Yvect = np.zeros(xint*yint)
    Uvect = np.zeros(xint*yint)
    Vvect = np.zeros(xint*yint)
    k = 0
    for i in X:
        for j in Y:
            mp.quiver(i,j,eqderx(i)(j),eqdery(i)(j))
    x = np.arange(0,xint,0.1)
    mp.show()

# testing with the first 1D-example given

testx = lambda x: lambda y: 1
testy = lambda x: lambda y: x/(1+y**2)
plot_tangent_arrow_field(testx,testy,7,7)

# testing with the second 2D-example given

test2x = lambda x: lambda y: -testy(x)(y)
test2y = lambda x: lambda y: -testx(x)(y)
plot_tangent_arrow_field(test2x,test2y,7,7)
